﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/view.Master" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>
<%@ Import Namespace="Workflow.Resource" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <script>

        function saveUser() {
            $('#form').form('submit', {
                url: '/User/SaveUser',
                success: function (data) {
                    eval('data=' + data);
                    if (data.Success) {
                        // _user_form.form('clear');
                        $.messager.alert('<%=Global.InfoTitle%>', data.Message, 'info', toBack);

                       // $.messager.alert('<%=Global.InfoTitle%>', data.Message, 'info');
                    } else {
                        $.messager.alert('<%=Global.ErrorTitle%>', data.Message, 'error', toBack);

                      //  $.messager.alert('<%=Global.ErrorTitle%>', data.Message, 'error');
                    }
                    
                   // window.location = '/User/Index';
                },
                onSubmit: function () {
                    //if (_user_form.valid())
                   
                    return $('#form').form('validate');
                    // else
                    //    return false;
                }
            });
        }
        function toBack() {
            window.location = '/User/Index';
        }


        $(function () {
            $('#Group').combobox({ url: '/User/GetGroup',
                valueField: 'GroupCode',
                textField: 'GroupName',
                onSelect: function (node) {
                    $('#NextStepUser').combobox('setValue', '');
                    $('#NextStepUser').combobox('disable');
                    // alert(node.FolderCode);
                    $('#Role').combobox({
                        disabled: false,
                        url: '/User/GetRole?id=' + node.GroupCode,
                        valueField: 'RoleCode',
                        textField: 'RoleName',
                        onSelect: function (node) {
                           
                            // alert(node.FolderCode);
                            $('#NextStepUser').combobox({
                                disabled: false,
                                url: '/User/GetUserList?id=' + node.RoleCode,
                                valueField: 'UserID',
                                textField: 'UserName'
                            });
                        }
                    });
                }
            });
        });
        $(document).ready(function () {

            $('#Group').combobox('setValue', '<%= ((Workflow.Model.User)this.ViewData["entity"]).GroupId==null?1:((Workflow.Model.User)this.ViewData["entity"]).GroupId.GroupCode %>');

            var groupid = $('#Group').combobox('getValue');

            $('#Role').combobox({
                disabled: false,
                url: '/User/GetRole?id=' + groupid,
                valueField: 'RoleCode',
                textField: 'RoleName',
                onSelect: function (node) {

                    // alert(node.FolderCode);
                    $('#NextStepUser').combobox({
                        disabled: false,
                        url: '/User/GetUserList?id=' + node.RoleCode,
                        valueField: 'UserID',
                        textField: 'UserName'
                    });
                }
            });
            $('#Role').combobox('setValue', '<%= ((Workflow.Model.User)this.ViewData["entity"]).RoleId==null?1:((Workflow.Model.User)this.ViewData["entity"]).RoleId.RoleCode %>');
           
            var Roleid = $('#Role').combobox('getValue');
            $('#NextStepUser').combobox({
                disabled: false,
                url: '/User/GetUserList?id=' + Roleid,
                valueField: 'UserID',
                textField: 'UserName'
            });

            $('#NextStepUser').combobox('setValue', '<%= ((Workflow.Model.User)this.ViewData["entity"]).NextStepUser==null?0:((Workflow.Model.User)this.ViewData["entity"]).NextStepUser.UserID %>');
        });
  
    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <form id="form" method="post" action="/User/SaveUser/">
    <input type="hidden" id="UserID"  name="entity.UserID" value="<%= ((Workflow.Model.User)this.ViewData["entity"]).UserID %>" />
    <div class="panel">
        <div class="panel-header">
            <%=Global.Information%></div>
        <div class="panel-body">
            <table style="background: #fafafa; text-align: center; width:100%;height:160px">

                <tr>
                    <td align="right" width="20%">
                        <%=Global.username%>:
                    </td>
                    <td align="right" width="5%">
                       &nbsp;
                    </td>
                    <td align="left" width="75%">
                        <input type="text" class="easyui-validatebox" required="true" maxlength="30"  validType="length[1,30]" style="width: 200px" id="UserName" name="entity.UserName" value="<%= ((Workflow.Model.User)this.ViewData["entity"]).UserName %>" />
                    </td>
                </tr>
                <tr>
                    <td align="right">
                        <%=Global.Group%>:
                    </td>
                    <td align="right" >
                       &nbsp;
                    </td>
                    <td align="left">
                        <input id="Group"  name="Group" class="easyui-combobox" style="width: 200px" url=""
                            valuefield="GroupCode" textfield="GroupName" editable="false">
                    </td>
                </tr>
                <tr>
                    <td align="right">
                        <%=Global.Role%>:
                    </td><td align="right" >
                       &nbsp;
                    </td>
                    <td align="left">
                        <input id="Role"  name="Role" class="easyui-combobox" style="width: 200px" url=""
                            valuefield="RoleCode" textfield="RoleName" editable="false">
                    </td>
                </tr>
                <tr>
                    <td align="right">
                         <%=Global.Email%>:
                    </td><td align="right" >
                       &nbsp;
                    </td>
                    <td align="left">
                        <input type="text" required="true" invalidMessage="<%= Global.invaildeamil %>" missingMessage="<%=Global.notempty %>" class="easyui-validatebox"  validType="email" style="width: 200px" id="email" name="entity.Email" value="<%= ((Workflow.Model.User)this.ViewData["entity"]).Email %>" />
                    </td>
                </tr>
                <tr>
                    <td align="right">
                       <%=Global.NextStep%>:
                    </td><td align="right" >
                       &nbsp;
                    </td>
                    <td align="left">
                        <input id="NextStepUser"  name="NextStepUser" class="easyui-combobox" style="width: 200px"
                            valuefield="UserID" textfield="UserName" editable="false" disabled="true">
                    </td>
                </tr>
                <tr>
                    <td align="right">
                       
                    </td><td align="right" >
                       &nbsp;
                    </td>
                    <td align="left">
                       
        <a href="##" onclick="saveUser()" class="easyui-linkbutton" id="btn-save" icon="icon-save">
            <%=Global.save%></a> <a href="##" onclick="toBack()" class="easyui-linkbutton" id="btn-cancel"
                icon="icon-undo"><%=Global.back%></a>
  
                    </td>
                </tr>
                 
            </table>
        </div>
    </div>
    
    </form>
</asp:Content>
